/** 
 * @author (Gruppe G) 
 * @version (04/17/2012)
 */

package ModelLayer;
import java.util.ArrayList;

public class MovieCollection
{
    private static MovieCollection instance;
    private ArrayList<DVD> DVDList;
    
    /**
     * Constructor for objects of class MovieCollection
     */
    public MovieCollection()
    {
        DVDList = new ArrayList<DVD>();
    }
    
    /**
     * Creates an instance of the MovieCollection.
     */
    public static MovieCollection getInstance()
    {
        if (instance == null)
        {
            instance = new MovieCollection();
        }
        return instance;
    }
    
    /**
     * Creating a movie entry in the array.
     */
    public void addDVD(DVD newDVD)
    {
        DVDList.add(newDVD);
    }
    
    /**
     * Finds a dvd via its title in array.
     * 
     * @param title the title to be used in search
     */
    public DVD findDVD(String title)
    {
        DVD dvd = null;
        int index = 0;
        boolean found = false;
        while(index < DVDList.size() && !found)
        {
            dvd = DVDList.get(index);
            if(dvd.getTitle().equals(title))
            {
                found = true;
            }
            else
            {
                index++;
            }
        }
        return dvd;
    }
    
    /**
     * Deletes a movie via its title in array.
     * 
     * @param title the title to be used in the deletion
     */
    public boolean deleteDVD(String title)
    {
        DVD dvd = null;
        int index = 0;
        boolean found = false;
        while(index < DVDList.size() && !found)
        {
            dvd = DVDList.get(index);
            if(dvd.getTitle().equals(title))
            {
                found = true;
                DVDList.remove(index);
            } 
            else
            {
                index++;
            }
        }
        return found;
    }
    
    /**
     * Listes all movies in array.
     */
    public ArrayList<DVD> listAllDVD()
    {
        return DVDList;
    }
    
}